package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.config.domain.EcardServeLibraryConfig;
import com.xydtech.ecard.config.service.IEcardServeLibraryConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子名片文库模块功能配置Controller
 *
 * @author yuzhiguo
 * @date 2024-09-18 上午10:55
 */
@Controller
@RequestMapping("/ecard/config/serveLibraryConfig")
public class EcardServeLibraryConfigController extends BaseController {
    private String prefix = "ecard/config/serveLibraryConfig";

    @Autowired
    private IEcardServeLibraryConfigService ecardServeLibraryConfigService;

    @RequiresPermissions("ecard:config:serveLibraryConfig:view")
    @GetMapping()
    public String serveLibraryConfig()
    {
        return prefix + "/serveLibraryConfig";
    }

    /**
     * 查询电子名片文库模块功能配置列表
     */
    @RequiresPermissions("ecard:config:serveLibraryConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardServeLibraryConfig ecardServeLibraryConfig)
    {
        startPage();
        List<EcardServeLibraryConfig> list = ecardServeLibraryConfigService.selectEcardServeLibraryConfigList(ecardServeLibraryConfig);
        return getDataTable(list);
    }

    /**
     * 导出电子名片文库模块功能配置列表
     */
    @RequiresPermissions("ecard:config:serveLibraryConfig:export")
    @Log(title = "电子名片文库模块功能配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardServeLibraryConfig ecardServeLibraryConfig)
    {
        List<EcardServeLibraryConfig> list = ecardServeLibraryConfigService.selectEcardServeLibraryConfigList(ecardServeLibraryConfig);
        ExcelUtil<EcardServeLibraryConfig> util = new ExcelUtil<EcardServeLibraryConfig>(EcardServeLibraryConfig.class);
        return util.exportExcel(list, "电子名片文库模块功能配置数据");
    }

    /**
     * 新增电子名片文库模块功能配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片文库模块功能配置
     */
    @RequiresPermissions("ecard:config:serveLibraryConfig:add")
    @Log(title = "电子名片文库模块功能配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardServeLibraryConfig ecardServeLibraryConfig)
    {
        return toAjax(ecardServeLibraryConfigService.insertEcardServeLibraryConfig(ecardServeLibraryConfig));
    }

    /**
     * 修改电子名片文库模块功能配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EcardServeLibraryConfig ecardServeLibraryConfig = ecardServeLibraryConfigService.selectEcardServeLibraryConfigById(id);
        mmap.put("ecardServeLibraryConfig", ecardServeLibraryConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片文库模块功能配置
     */
    @RequiresPermissions("ecard:config:serveLibraryConfig:edit")
    @Log(title = "电子名片文库模块功能配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardServeLibraryConfig ecardServeLibraryConfig)
    {
        return toAjax(ecardServeLibraryConfigService.updateEcardServeLibraryConfig(ecardServeLibraryConfig));
    }

    /**
     * 删除电子名片文库模块功能配置
     */
    @RequiresPermissions("ecard:config:serveLibraryConfig:remove")
    @Log(title = "电子名片文库模块功能配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ecardServeLibraryConfigService.deleteEcardServeLibraryConfigByIds(ids));
    }

}
